var VideoPage = {
    currCateID: 0,
    currCateName: '',
    totalVideo: 0,
    totalPage: 0,
    currPage: 0,
    listVideoIds: [],
    excluse: [],
    baseUrl: '',
    listVideoEleId: '',
    loadingEleId: '',
    __gotoPage: function(page, cateID){
        var data = null;
        this.currPage = page;
        if (typeof cateID != 'undefined'){
            this.currCateID = cateID;
        }
        data = {
            cateID: this.currCateID,
            currPage: this.currPage,
            excluse: this.excluse
        }
        var keyCache = 'video-' + this.currCateID + '-' + this.currPage;
        var cachedContent = null;
        /* Get cache by jcache */
        try{
            cachedContent = $.jCache.getItem(keyCache);
        }
        catch(ex){
            cachedContent = null;
        }
        
        /* If miss cache */
        if (cachedContent == null || typeof cachedContent == 'undefined')
        {
            $.ajax({
                type: 'get',
                url: this.baseUrl + '/video/ajax-load-list-video',
                data: data,
                dataType: 'json',
                async: false,
                beforeSend: function(){
                    $('#' + VideoPage.listVideoEle).html($('#' + VideoPage.loadingEleId).html());
                },
                success:function(response)
                {
                    cachedContent = response;
                    $.jCache.setItem(keyCache, response);
                }
            });
        }
        
        if(!cachedContent.error){
            var listVideoID = $('#' + this.listVideoEleId);
            listVideoID.fadeOut(100, function(){
                listVideoID.html(cachedContent.html).fadeIn(200);
                PVWidget.getViews();
            });
            if (cachedContent.ext != null){
                this.totalVideo = cachedContent.ext.totalVideo;
                this.totalPage = cachedContent.ext.totalPage;
                this.listVideoIds = cachedContent.ext.listVideoIds;
                this.currPage = cachedContent.ext.currPage;
            }
        }
    },
    init: function(options){
        this.currCateID = options.currCateID;
        this.currCateName = options.currCateName;
        this.totalVideo = options.totalVideo;
        this.totalPage = options.totalPage;
        this.currPage = options.currPage;
        this.excluse = options.excluse;
        this.baseUrl = options.baseUrl;
        this.listVideoEleId = options.listVideoEleId;
        this.loadingEleId = options.loadingEleId;
    },
    prevPage: function(){
        this.__gotoPage(this.currPage - 1);
    },
    nextPage: function(){
        this.__gotoPage(this.currPage + 1);
    },
    loadListVideo: function(cateId){
        $('#list_cate_video').find('li').removeClass('active');
        $('#menu_' + cateId).addClass('active');
        this.__gotoPage(1, cateId);
    }
}